package com.learning.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.learning.constant.JwtClaimsConstant;
import com.learning.dto.LoginDTO;
import com.learning.dto.PageQueryDTO;
import com.learning.entity.Teacher;
import com.learning.properties.JwtProperties;
import com.learning.result.PageResult;
import com.learning.result.Result;
import com.learning.service.ITeacherService;
import com.learning.utils.JwtUtil;
import com.learning.vo.LoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 教师表 前端控制器
 * </p>
 *
 * @author itRao
 * @since 2024-05-23
 */
@RestController("adminTeacherController")
@RequestMapping("/admin/teacher")
@Slf4j
@RequiredArgsConstructor
@Api(tags = "教师相关接口")
public class TeacherController {

    private final ITeacherService teacherService;

    /**
     * 分页查询教师信息
     *
     * @param pageQueryDTO
     * @return
     */
    @ApiOperation("分页查询教师信息")
    @GetMapping("/page")
    public Result<PageResult<Teacher>> pageQuery(PageQueryDTO pageQueryDTO) {
        IPage<Teacher> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
        IPage<Teacher> teacherIPage = teacherService.page(page);

        List<Teacher> teachers = teacherIPage.getRecords();
        if (CollectionUtils.isEmpty(teachers)) {
            return Result.success(new PageResult(teacherIPage.getTotal(), teacherIPage.getPages(), null));
        }

        return Result.success(new PageResult(teacherIPage.getTotal(), teacherIPage.getPages(), teacherIPage.getRecords()));
    }
}
